﻿using E_GovernmentSystem.Models;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace E_GovernmentSystem.Controllers
{
    public class LoginController : Controller
    {

        //配置数据库上下文
        private readonly SqlSugar.ISqlSugarClient db;

        public LoginController(SqlSugar.ISqlSugarClient _db)
        {
            this.db = _db;
        }

        //登录方法
        public IActionResult getLogin(string username,string password)
        {
            bool res = false;

            var userinfo = db.Queryable<usertable>().Where(a => a.UserName == username && a.UserPassword == password).First();

            if (userinfo != null)
            {
                res = true;
                //将登录信息存储在session中
                HttpContext.Session.SetString("userInfo",JsonConvert.SerializeObject(userinfo));
            }

            return Json(res);
        }
        //登陆页面
        public IActionResult Index()
        {
            //进行一次尝试
            //db.DbFirst.CreateClassFile("E:\\Learn\\短训\\.NET\\.NET Core\\源码\\电子政务系统\\hwd\\e-government-system\\E-GovernmentSystem\\Models", "E_GovernmentSystem.Models");
            return View();
        }

    }
}
